import type { EmployeeResp } from './employee'
import http from '@/utils/http'

const BASE_URL = '/system/role'

export interface RoleResp {
  id: string
  code: string
  name: string
  preserved: boolean
  sort: number
  description: string
}

export interface RoleDetailResp extends RoleResp {

}

export interface RoleQuery extends SortQuery {
  code?: string
  name?: string
}

export interface RoleEmployeeQuery {
  roleId: string
}

export interface RoleEmployeePageQuery extends PageQuery {
}

/** @desc 查询角色列表 */
export function getList(query: RoleQuery) {
  return http.get<RoleResp[]>(`${BASE_URL}/list`, query)
}

/** @desc 查询角色详情 */
export function getDetail(id: string) {
  return http.get<RoleDetailResp>(`${BASE_URL}/detail/${id}`)
}

/** @desc 创建角色 */
export function create(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改角色 */
export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

/** @desc 删除角色 */
export function remove(id: string) {
  return http.post(`${BASE_URL}/delete/${id}`)
}

/** @desc 查询角色资源列表 */
export function getRoleResourceCodeList(roleId: string) {
  return http.get<string[]>(`${BASE_URL}/resource/list?roleId=${roleId}`)
}

/** @desc 更新角色资源列表 */
export function updateRoleResource(data: any) {
  return http.post(`${BASE_URL}/resource/update`, data)
}

/** @desc 查询角色员工列表 */
export function getRoleEmployeePage(query: RoleEmployeePageQuery) {
  return http.get<EmployeeResp[]>(`${BASE_URL}/employee/page`, query)
}

/**
 * 从角色员工列表中移除员工
 * @param data
 */
export function removeEmployee(data: { roleId: string, employeeId: any }) {
  return http.post(`${BASE_URL}/employee/remove`, data)
}

/**
 * 添加角色员工
 * @param data
 */
export function createRoleEmployee(data: { roleId: string, employeeId: any }) {
  return http.post(`${BASE_URL}/employee/create`, data)
}
